//
//  collectionViewController.m
//  ui豆瓣
//
//  Created by lirui on 15/12/28.
//  Copyright © 2015年 www.lanou3g.com蓝鸥科技. All rights reserved.
//

#import "collectionViewController.h"
#import "myCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "moviemodel.h"
@interface collectionViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property(nonatomic,retain)NSMutableArray *arr;

@end

@implementation collectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [ UIColor whiteColor];
    UICollectionViewFlowLayout  *layout = [[ UICollectionViewFlowLayout alloc] init];
    layout.itemSize =CGSizeMake((375 -35 ) / 3, 200 );
    layout.minimumLineSpacing = 0;
    //列
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(5, 10, 64, 10);

    UICollectionView *collectionview = [[ UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
    collectionview.dataSource = self;
    collectionview.delegate = self;
    collectionview.backgroundColor = [ UIColor whiteColor];
    [self.view addSubview:collectionview];
    //注册
    [collectionview registerClass:[ myCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self data];
    
}
-(void)data
{   NSString *path = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"plist"];
    NSArray *tempArr = [ NSArray arrayWithContentsOfFile:path];
    self.arr = [ moviemodel modelHanderWithArray:tempArr];
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _arr.count;
    
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
   myCollectionViewCell *cell =[ collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    moviemodel *m = _arr[ indexPath.item];
    cell.name.text = m.title;
     [cell.imgview sd_setImageWithURL:[NSURL URLWithString:m.largeimage]];
    cell.fen.text = m.rating ;
    NSLog(@"%@", cell.fen.text);
    NSInteger key = [m.rating integerValue];
    NSLog(@"1222 %ld", key);
    
    
switch (key) {
            case 0:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
               break;
                 case 1:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_half@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
            default:
        case 2:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        break;
case 3:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_half@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_gray@2x"];

                break;
    case 4:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_gray@2x"];

        break;
    case 5:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_half@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_gray@2x"];

        break;
        
        case 6:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_gray@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_gray@2x"];

        break;
        case 7:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_half@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_gray@2x"];

        break;
        case 8:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_gray@2x"];

        break;
        case 9:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_half@2x"];

        break;
        case 10:
        cell.star1.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star2.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star3.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star4.image =[ UIImage imageNamed:@"ic_star_red@2x"];
        cell.star5.image =[ UIImage imageNamed:@"ic_star_red@2x"];

        break;
        
        }
  
 
    
    return cell;
}
-(void)star
{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
